package com.squirrel.common.response;

import com.squirrel.common.response.code.IEnum;

/**
 * @Description ResponseResultUtil 工具类
 * @Author 关远键
 * @Version v1.0.0
 * @Date 2021/11/9 14:24
 */
public class ResponseResultUtils<T> {
    /**
     * 成功
     * @param message
     * @param <T>
     * @return
     */
    public static <T> ResponseResult<T> success(String message) {
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(200);
        result.setMessage(message);
        return result;
    }

    /**
     * 成功
     * @param t
     * @param <T>
     * @return
     */
    public static <T> ResponseResult<T> success(T t) {
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(200);
        result.setMessage("操作成功");
        result.setData(t);
        return result;
    }

    public static <T> ResponseResult<T> danmuSuccess(T t) {
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(0);
        result.setMessage("操作成功");
        result.setData(t);
        return result;
    }

    /**
     * 成功
     *
     * @param iEnum
     * @param t
     * @param <T>
     * @return
     */
    public static <T> ResponseResult<T> success(IEnum iEnum, T t) {
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(iEnum.getCode());
        result.setMessage(iEnum.getMessage());
        result.setData(t);
        return result;
    }

//    public static <T> ResponseResult<T> loginSuccess(T t) {
//        return success(CodeEnum.LOGIN_SUCCESS, t);
//    }
//
//    public static <T> ResponseResult<T> registerSuccess(T t) {
//        return success(CodeEnum.REGISTER_SUCCESS, t);
//    }
//
//    public static <T> ResponseResult<T> modifySuccess(T t) {
//        return success(CodeEnum.MODIFY_SUCCESS, t);
//    }

    /**
     * 失败
     * @param iEnum
     * @param <T>
     * @return
     */
    public static <T> ResponseResult<T> error(IEnum iEnum) {
        return error(iEnum.getCode(), iEnum.getMessage());
    }

    /**
     * 失败
     * @param message
     * @param <T>
     * @return
     */
    public static <T> ResponseResult<T> error(String message) {
        return error(400, message);
    }

    /**
     * 失败
     * @param message
     * @param <T>
     * @return
     */
    public static <T> ResponseResult<T> error(Integer code, String message) {
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

}
